home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / libgutil / hypcurve.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  101 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    hypcurve -
  19.  *        Create hyperbolic and power curves for correcting
  20.  *    printers. 
  21.  *
  22.  *                Paul Haeberli - 1990
  23.  */
  24. #include "math.h"
  25. #include "stdio.h"
  26.  
  27. float hypfunc(hypval,powval,x)
  28. float hypval, powval, x;
  29. {
  30.     float b, y;
  31.  
  32.     if(x<0.00001)
  33.     return 0.0;
  34.     if(hypval<0.99999 || hypval>1.00001) {
  35.     b = (1.0/hypval) - hypval;
  36.     y = 1.0-(1.0/((x*b)+hypval) - hypval)/b;
  37.     } else 
  38.     y = x;
  39.     return pow(y,powval);
  40. }
  41.  
  42. float hypinvfunc(hypval,powval,y)
  43. float hypval,powval,y;
  44. {
  45.     float b, x;
  46.  
  47.     if(y<0.00001)
  48.     return 0.0;
  49.     y = pow(y,1.0/powval);
  50.     if(hypval<0.99999 || hypval>1.00001) {
  51.     hypval = 1.0/hypval;
  52.     b = (1.0/hypval) - hypval;
  53.     x = 1.0-(1.0/((y*b)+hypval) - hypval)/b;
  54.     } else 
  55.     x = y;
  56.     return x;
  57. }
  58.  
  59. hypcurve(hypval,powval,tab)
  60. float hypval, powval;
  61. short tab[256];
  62. {
  63.     float x, y;
  64.     int i;
  65.  
  66.     for(i=0; i<256; i++) {
  67.     x = i/255.0;
  68.     y = hypfunc(hypval,powval,x);
  69.     tab[i] = (255*y)+0.5;
  70.     }
  71. }
  72.  
  73.  
  74. hypinvcurve(hypval,powval,tab)
  75. float hypval, powval;
  76. short tab[256];
  77. {
  78.     float x, y;
  79.     int i;
  80.  
  81.     for(i=0; i<256; i++) {
  82.     x = i/255.0;
  83.     y = hypinvfunc(hypval,powval,x);
  84.     tab[i] = (255*y)+0.5;
  85.     }
  86. }
  87.  
  88. printtab(tab)
  89. short tab[256];
  90. {
  91.     int i;
  92.  
  93.     fprintf(stderr,"cortab: \n");
  94.     for(i=0; i<256; i++) {
  95.     if((i%16) == 0)
  96.         fprintf(stderr,"\n");
  97.     fprintf(stderr,"%03d ",tab[i]);
  98.     }
  99.     fprintf(stderr,"\n");
  100. }
  101.